class Solution {
public:
    int numDecodings(string s)
    {
        if (s[0] == '0')return 0;
        int n = s.size();
        if (n == 1)return 1;
        vector<int> dp(n);
        dp[0] = 1; dp[1] = 0;
        if ((s[1] - '0') >= 1 && (s[1] - '0') <= 9)dp[1]++;
        if ((s[1] - '0') + (s[0] - '0') * 10 <= 26)dp[1]++;
        for (int i = 2; i < n; i++)
        {
            int r1 = 0, r2 = 0;
            if (s[i] != '0')r1 = dp[i - 1];
            if (((s[i] - '0') + (s[i - 1] - '0') * 10) >= 10 && ((s[i] - '0') + (s[i - 1] - '0') * 10) <= 26)r2 = dp[i - 2];
            dp[i] = r1 + r2;
        }
        return dp[n - 1];


    }
};